package cn.gson.crm.control.allot;

import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gson.crm.control.base.BaseServlet;
import cn.gson.crm.model.dao.AllotDao;
import cn.gson.crm.model.dao.ClazzDao;
import cn.gson.crm.model.dao.CooperationDao;
import cn.gson.crm.model.dao.FollowDao;
import cn.gson.crm.model.dao.StudentDao;
import cn.gson.crm.model.entity.Clazz;
import cn.gson.crm.model.po.CooperationsPo;
import cn.gson.crm.model.po.FollowPo;
import cn.gson.crm.model.po.StaffPo;
import cn.gson.crm.model.po.StudentPo;
@WebServlet("/allot/one")
public class AllotOneServlet extends BaseServlet{
	private StudentDao studentDao = new StudentDao();
	private CooperationDao cooperationDao = new CooperationDao();
	private AllotDao allotDao = new AllotDao();
	private FollowDao followDao = new FollowDao();
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Override
	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String staffid = request.getParameter("staffid");
 		request.setAttribute("staffid", staffid);
 		String coo = request.getParameter("coopstaffid");
		String stuId = request.getParameter("stuid");
		String cmethod = request.getParameter("cmethod");
		if("cooperation".equals(cmethod)){
			request.setAttribute("cmethod", cmethod);
		}
		 if("newcoop".equals(cmethod)){
			if(cooperationDao.getCooperation(coo, stuId)){
				cooperationDao.insertCooperation(coo, stuId);
			}
		}
		List<StaffPo> data = allotDao.getStaffOtherList(staffid);
		if(data != null){
			request.setAttribute("StaffList", data);
		}
		List<FollowPo> FollowPoList = followDao.getFollowPoList(stuId);
		if(FollowPoList != null){
			request.setAttribute("FollowPoList", FollowPoList);
		}
		String clazz=request.getParameter("clazzname");
		List<Clazz> listclazz=null;
		if(clazz==null||clazz.isEmpty()){
			 listclazz=new ClazzDao().getClazz();
		}else{
		 listclazz=new ClazzDao().getClazz(clazz);
		}
		//是否缴费
		String total_student_id=request.getParameter("total_student_id");
		request.setAttribute("total_student_id", total_student_id);
		//是否分配咨询师
		String staffname=request.getParameter("staffname");
		request.setAttribute("staffname", staffname);
		request.setAttribute("clazz", clazz);
		StudentPo studentPo = studentDao.getOneStudent(stuId);
		List<CooperationsPo> cooperationsPoList = cooperationDao.getCooperationsList(stuId);
		request.setAttribute("studentPo", studentPo);
		request.setAttribute("cooperationsPoList", cooperationsPoList);
		request.setAttribute("listclazz", listclazz);
		forward("allot/allot_one_student.jsp");
	}
	@Override
	protected void post(HttpServletRequest request, HttpServletResponse response) throws Exception {
		get(request, response);
	}

}
